/**
 * 
 */
package cz.cvut.fit.crhonjar.mi.run.hawera.tree.statement;

import cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor;
import cz.cvut.fit.crhonjar.mi.run.hawera.tree.expression.ExpressionTree;

/**
 * @author Jarec
 * 
 */
public class IfTree extends StatementTree {

	private ExpressionTree ifCondition;
	private StatementTree ifPart;
	private StatementTree elsePart;

	/**
	 * constructs ifStatementTree only with condition and ifPart, elsePart will
	 * be empty
	 * 
	 * @param condition
	 * @param ifPart
	 */
	public IfTree(ExpressionTree condition, StatementTree ifPart) {
		this.log.debug("> IfTree");
		if (condition == null) {
			final String message = "Cannot build IfTree with null Condition";
			this.log.error(message);
			throw new NullPointerException(message);
		}
		if (ifPart == null) {
			final String message = "Cannot build IfTree with null ifPart";
			this.log.error(message);
			throw new NullPointerException(message);
		}
		this.ifCondition = condition;
		this.ifPart = ifPart;
		this.elsePart = null;
		this.log.debug("< IfTree");
	}

	/**
	 * constructs whole ifTree including condition, if-, and else- part
	 * 
	 * @param condition
	 * @param ifPart
	 * @param elsePart
	 */
	public IfTree(ExpressionTree condition, StatementTree ifPart,
			StatementTree elsePart) {
		this.log.debug("> IfTree");
		if (condition == null) {
			final String message = "Cannot build IfTree with null Condition";
			this.log.error(message);
			throw new NullPointerException(message);
		}
		if (ifPart == null) {
			final String message = "Cannot build IfTree with null ifPart";
			this.log.error(message);
			throw new NullPointerException(message);
		}
		if (elsePart == null) {
			this.log.warn("Using big constructor to construct iftree without elsePart!");
		}
		this.ifCondition = condition;
		this.ifPart = ifPart;
		this.elsePart = elsePart;
		this.log.debug("< IfTree");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cz.cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitorAcceptor#accept(cz
	 * .cvut.fit.crhonjar.mi.run.hawera.tree.TreeVisitor)
	 */
	@Override
	public void accept(TreeVisitor visitor) {
		visitor.visitIf(this);

	}

	/**
	 * @return the elsePart
	 */
	public StatementTree getElsePart() {
		this.log.debug(">< getElsePart exists?: {}", this.elsePart != null);
		return this.elsePart;
	}

	/**
	 * @return the ifCondition
	 */
	public ExpressionTree getIfCondition() {
		this.log.debug(">< getIfCondition");
		return this.ifCondition;
	}

	/**
	 * @return the ifPart
	 */
	public StatementTree getIfPart() {
		this.log.debug(">< getIfPart");
		return this.ifPart;
	}

}
